﻿
//--> Loth 2011 
//--> Full away3d pannel 

package chamans
{   
	import com.bit101.components.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
		
		public class SYS_pannel extends Sprite
		{      
			private var O:Object;
			private var iner:Object;
			private var content:Sprite;
			private var FONT:SYS_fonts;
			private var open:Boolean=false;
			private var openplus:Boolean=false;
			
			public function SYS_pannel(o:Object, F:SYS_fonts) : void
			{
				Style.setStyle(Style.DARK);
				Style.fontSize=12;
				Style.LABEL_TEXT=0xDADED3;
				Style.BUTTON_FACE=0xBD3436;
				
				Style.BUTTON_DOWN=0x623436;
				Style.fontName="Myriad Web Pro";
				Style.embedFonts=true;
				Style.PANEL=0xFFFF66;
				O=o; FONT=F;
			}
			public function ADD(n:int, H:int=275 ) : void
			{
				if(open) Delete();
				content=new Sprite();
				content.x=O.size.x-230;
				content.mouseEnabled=false; 
				//O.SYS.MODE(content)
				open=true;
				iner={
				name:<xml><pannel></pannel></xml>, titre:new SYS_text(FONT.CSS, 210, 0, 15),
				bg:O.TOOL.CARRE({color:0x000000, alpha:.6, w:220, h:H, r:0, y:10, line:false }),
				outtop:O.TOOL.CARRE({color:0x000000, alpha:0, w:200, h:30, r:0, x:10, y:10, line:false}),
				outbg:O.TOOL.CARRE({color:0xFF3436, alpha:1, w:10, h:10, r:10, y:20,line:false}),
				line:O.TOOL.CARRE({color:linecolor, alpha:linealpha, w:195, h:1, x:10, y:40}),
				line2:O.TOOL.CARRE({color:linecolor, alpha:linealpha, w:1, h:10, y:30, x:205}),
				out:new Sprite(), top:new Sprite()
				}
				with(iner){	out.x=200;
					out.buttonMode=true;
					out.addChild(outbg); top.addChild(outtop);
					top.mouseChildren=false;
					top.addEventListener('mouseDown', DRAG);
					out.addEventListener('rollOver', swap);
					out.addEventListener('rollOut', swapoff);
					out.addEventListener('click', off);
					content.addChild(top);
				 	content.addChild(line); content.addChild(line2);
					top.addChild(titre); content.addChild(out);
					switch(n){ // base selector
						case 1:name.pannel="Viewport"; Viewport();  break;
						case 2:name.pannel="Ligths"; Lights(); break;
						case 3:name.pannel="Materials"; Material(); break;
						case 4:name.pannel="Physics"; Physic(); break;
					}
					titre.readXML(name);
					O.stage.addChild(bg);bg.x=content.x
					O.stage.addChild(content);	
				}}
			
			private function Delete() : void
			{
				with(iner){
					out.removeChild(outbg);
					top.removeChild(titre);
					top.removeEventListener('mouseDown', DRAG);
					out.removeEventListener('rollOver', swap);
					out.removeEventListener('rollOut', swapoff);
					out.removeEventListener('click', off);
				}
				while(content.numChildren) content.removeChildAt(0);
				O.stage.removeChild(content);
				O.stage.removeChild(iner.bg);
				content=null;
				open=false;
				iner=null;
			}
			private function upbg(H:int) : void
			{
				iner.bg.graphics.clear()
				iner.bg=O.TOOL.CARRE({obj:iner.bg,color:0x000000, alpha:.6, w:220, h:H, r:0, y:10, line:false })
			}
			// drag
			private function DRAG(e:MouseEvent) : void
			{  
				iner['x']=content.mouseX;
				iner.top.addEventListener('rollOut', DRAGoff);
				iner.top.addEventListener('mouseMove', DRAGon);
				iner.top.addEventListener('mouseUp', DRAGoff);
				iner.top.buttonMode=true;
			}
			private function DRAGon(e:MouseEvent) : void
			{  
				content.x=iner.bg.x=O.stage.mouseX-iner.x;
			}
			private function DRAGoff(e:MouseEvent) : void
			{  
				iner.top.removeEventListener('rollout', DRAGoff);
				iner.top.removeEventListener('mouseMove', DRAGon);
				iner.top.removeEventListener('mouseUp', DRAGoff);
			}
			// over out del
			private function swap(e:MouseEvent) : void
			{  
				O.TOOL.color(e.target, 0xE5CC19)
			}
			private function swapoff(e:MouseEvent) : void
			{
				O.TOOL.color(e.target);
			}
			private function off(e:MouseEvent) : void
			{
				Delete();
			}
	
		 	private function sep(Y:int=40, H:int=10, X:int=205) : void{
			var line:Shape=O.TOOL.CARRE({color:linecolor, alpha:linealpha, w:195, h:1, x:10, y:Y});
		 	var line2:Shape=O.TOOL.CARRE({color:linecolor, alpha:linealpha, w:1, h:H, y:Y-H, x:X});
			content.addChild(line); content.addChild(line2);
		   } 
			private function sep2(Y:int=40, H:int=10, X:int=205, B:Boolean=false) : void{
				var t:int=195
				if(B){var round:Shape=O.TOOL.CARRE({color:linecolor, alpha:linealpha, w:10, h:10, r:10, x:200 ,y:Y-5,line:false});
					tmpAdd.addChild(round);t=190;
				}
				var line:Shape=O.TOOL.CARRE({color:linecolor, alpha:linealpha, w:t, h:1, x:10, y:Y});
				var line2:Shape=O.TOOL.CARRE({color:linecolor, alpha:linealpha, w:1, h:H, y:Y-H, x:X});
				tmpAdd.addChild(line); tmpAdd.addChild(line2);
			}
			
			/////////////////////////////////////////
			//              VIEWPORT               //
			//             ALL SETTING             //
			/////////////////////////////////////////
			private function Viewport() : void
			{
				var txt00:Label=new Label(content, 15, 45, "Antialias");
				var radio1:RadioButton = new RadioButton(content, 80, 50, "0", true, q0);radio1.groupName="A";
			 	var radio2:RadioButton = new RadioButton(content, 110, 50, "2", false, q2);radio2.groupName="A";
				var radio3:RadioButton = new RadioButton(content, 140, 50, "4", false, q4);radio3.groupName="A";
				sep(70, 30, 10);
				var txt01:Label=new Label(content, 15, 75, "Shadows");
				var radio4:RadioButton = new RadioButton(content, 80, 80, "null", false, s0);radio4.groupName="B";
				var radio5:RadioButton = new RadioButton(content, 140, 80, "soft", true, s1);radio5.groupName="B";
				var radio6:RadioButton = new RadioButton(content, 80, 100, "filter", false,s2);radio6.groupName="B";
				var radio7:RadioButton = new RadioButton(content, 140, 100, "hard", false, s3);radio7.groupName="B";
				sep(120, 50);
			    var txt02:Label=new Label(content, 15, 125, "Fog");
				var radio8:RadioButton;
				var radio9:RadioButton;
				if(O.fog){
					radio8 = new RadioButton(content, 160, 130, "off", false, f0);
					radio9= new RadioButton(content, 130, 130, "on", true, f1);
				}else{
					radio8 = new RadioButton(content, 160, 130, "off", true, f0);
					radio9= new RadioButton(content, 130, 130, "on", false, f1);
				}
				radio8.groupName="C";
				radio9.groupName="C";
				var col:ColorChooser=new ColorChooser(content,50,125,O.FogColor, FogChangeColor);
				col.usePopup=(true);
				var Slide00:HUISlider = new HUISlider (content, 15, 145, 'Distance', FogChange);
			 	Slide00.setSliderParams(10, 6000, O.FogDistance );
				Slide00.labelPrecision=0;
				sep(170, 50, 10);
				var txt03:Label=new Label(content, 15, 175, "Camera");
				var radio10:RadioButton = new RadioButton(content, 80, 180, "normal", false, c0);radio10.groupName="D";
				var radio11:RadioButton = new RadioButton(content, 140, 180, "fps", true, c1);radio11.groupName="D";
				var Slide01:HUISlider = new HUISlider (content, 15, 195, 'Fov', FoVChange);
				var Slide02:HUISlider = new HUISlider (content, 15, 215, 'Far', FarChange);
				Slide01.setSliderParams(1, 170, O.view.camera.lens.fieldOfView );
				Slide01.labelPrecision=0;
				Slide02.setSliderParams(1000, 20000, O.view.camera.lens.far );
				Slide02.labelPrecision=0;
				sep(240, 70, 205);
				var comp:ComboBox=new ComboBox(content,40, 245,"Filter",["none", "bloom", "blur", "depth", "motion"])
				comp.addEventListener(Event.SELECT, FILTER);
				comp.width=140;
				tmpAdd=new Sprite();
				content.addChild(tmpAdd)
				sep2(270, 30, 10, true);
			}
			private function q0(e:Event):void { O.view.antiAlias=0; }
			private function q2(e:Event):void { O.view.antiAlias=2; }
			private function q4(e:Event):void { O.view.antiAlias=4; }
			private function s0(e:Event):void { O.Shadows(0); }
			private function s1(e:Event):void { O.Shadows(1); }
			private function s2(e:Event):void { O.Shadows(2); }
			private function s3(e:Event):void { O.Shadows(3); }
			private function f0(e:Event):void { O.Foger(false); }
			private function f1(e:Event):void { O.Foger(); }
			private function c0(e:Event):void { O.Camera.M.type="normal"; O.SYS.VISOR(false); }
			private function c1(e:Event):void { O.Camera.M.type="fps"; O.SYS.VISOR(true);}
			private function FogChange(e:Event):void { 
				O.distance_Fog(e.target.value)
			}
			private function FogChangeColor(e:Event):void { 
				O.FogColor=e.target.value
				O.color_Fog()
			}
			private function FoVChange(e:Event):void { 
				O.view.camera.lens.fieldOfView=e.target.value;
			}
			private function FarChange(e:Event):void { 
				O.view.camera.lens.far=e.target.value;
			}
			private function FILTER(e:Event):void { 
				DeleteFilter();
				var type:String=e.target.selectedItem;
				switch(type){
					case 'none':O.view.filters3d =[];
						sep2(270, 30, 10, true);
						upbg(275)
						break;
					case 'bloom':O.Bloom();
						var sx00:HUISlider = new HUISlider (tmpAdd, 15, 270, 'BlurX', bx00);
						var sx01:HUISlider = new HUISlider (tmpAdd, 15, 290, 'BlurY', bx01);
						var sx02:HUISlider = new HUISlider (tmpAdd, 15, 310, 'Threshold', bx02);
						var sx03:HUISlider = new HUISlider (tmpAdd, 15, 330, 'Exposure', bx03);
						var sx04:HUISlider = new HUISlider (tmpAdd, 15, 350, 'Quality', bx04);
						sx00.setSliderParams(0, 100, O.CurrentFilter.blurX );
						sx01.setSliderParams(0, 100, O.CurrentFilter.blurY );
						sx02.setSliderParams(0, 1, O.CurrentFilter.threshold );
						sx03.setSliderParams(0, 5, O.CurrentFilter.exposure );
						sx04.setSliderParams(0, 4, 0 );
						sx00.labelPrecision=sx01.labelPrecision=sx04.labelPrecision=0;
						sx03.labelPrecision=2;
						sx02.labelPrecision=2;
						sep2(375, 135, 10, true);
						upbg(380)
						break;
					case 'blur': O.Blur();
						var sx10:HUISlider = new HUISlider (tmpAdd, 15, 270, 'BlurX', bx10);
						var sx11:HUISlider = new HUISlider (tmpAdd, 15, 290, 'BlurY', bx11);
						sx10.setSliderParams(0, 100, O.CurrentFilter.blurX );
						sx11.setSliderParams(0, 100, O.CurrentFilter.blurY );
						sx10.labelPrecision=sx11.labelPrecision=0;
						sep2(315, 75, 10, true);
						upbg(320)
						break;
					case 'depth': O.Deep();
						var sx20:HUISlider = new HUISlider (tmpAdd, 15, 270, 'BlurX', bx20);
						var sx21:HUISlider = new HUISlider (tmpAdd, 15, 290, 'BlurY', bx21);
						var sx22:HUISlider = new HUISlider (tmpAdd, 15, 310, 'Range', bx22);
						sx20.setSliderParams(0, 100, O.CurrentFilter.maxBlurX );
						sx21.setSliderParams(0, 100, O.CurrentFilter.maxBlurY );
						sx22.setSliderParams(0, 4000, O.CurrentFilter.range )
						sx20.labelPrecision=sx21.labelPrecision=0;
						sx22.labelPrecision=0;
						sep2(335, 95, 10, true);
						upbg(340)
						break;
					case 'motion': O.MotionBlur();
						var sx30:HUISlider = new HUISlider (tmpAdd, 15, 270, 'strength', bx30);
						sx30.setSliderParams(0, 1, O.CurrentFilter.strength )
						sx30.labelPrecision=2;
						sep2(295, 55, 10, true);
						upbg(300)
						break;
				}
			}
			private function bx00(e:Event):void {//  O.CurrentFilter.blurX = e.target.value; 
				O.Bloom(e.target.value,O.CurrentFilter.blurY, O.CurrentFilter.threshold ,O.CurrentFilter.exposure, Q );
				}
			private function bx01(e:Event):void {//  O.CurrentFilter.blurY = e.target.value;
				O.Bloom(O.CurrentFilter.blurX,e.target.value, O.CurrentFilter.threshold ,O.CurrentFilter.exposure, Q );
			}
			private function bx02(e:Event):void {  O.CurrentFilter.threshold = e.target.value; }
			private function bx03(e:Event):void {  O.CurrentFilter.exposure = e.target.value; }
			private function bx04(e:Event):void {  Q=e.target.value;
			O.Bloom(O.CurrentFilter.blurX,O.CurrentFilter.blurY, O.CurrentFilter.threshold ,O.CurrentFilter.exposure, Q);
			}
			private function bx10(e:Event):void {O.Blur(e.target.value,O.CurrentFilter.blurY );}
			private function bx11(e:Event):void {O.Blur(O.CurrentFilter.blurX,e.target.value);}
			private function bx20(e:Event):void { O.Deep(e.target.value,O.CurrentFilter.maxBlurY );}
			private function bx21(e:Event):void {O.Deep(O.CurrentFilter.maxBlurX,e.target.value);}
			private function bx22(e:Event):void {  O.CurrentFilter.range = e.target.value; }
			private function bx30(e:Event):void {  O.CurrentFilter.strength = e.target.value; }
			private function DeleteFilter() : void
			{
				while(tmpAdd.numChildren) tmpAdd.removeChildAt(0);
			}
			//  END VIEWPORT
			
			/////////////////////////////////////////
			//                LIGHTS               //
			//             ALL SETTING             //
			/////////////////////////////////////////
			private function Lights() : void
			{
				var Liste:Array=new Array();
				for each(var l:* in O.LIGHT)Liste.push(l.name)
				var comp:ComboBox=new ComboBox(content,40, 45,"scene light",Liste);
				comp.width=140;
				comp.addEventListener(Event.SELECT, select_Light);
				
				//sep(70, 30, 10);
				tmpAdd=new Sprite();
				content.addChild(tmpAdd)
				sep2(70, 30, 10, true);
				upbg(75)
			}
			private function select_Light(e:Event):void { 
				DeleteFilter();
				var n:int=e.target.selectedIndex;
				var tend:int=145;
				CurrentLight=O.LIGHT[n];
				switch(O.LIGHT[n].name){
					case "sun": var l02:HUISlider = new HUISlider (tmpAdd, 15, 140, 'Time', L02);
						var l03:HUISlider = new HUISlider (tmpAdd, 15, 160, 'Azimut', L03)
						l02.setSliderParams(-90, 90,O.Lights.angle );
						l03.setSliderParams(0, 360,O.Lights.angle2 );
						l02.labelPrecision=0;
						l03.labelPrecision=0;
						tend=185;
						break;
					case "direct": ;break;
					case "point": ;break;
				}
				var l00:HUISlider = new HUISlider (tmpAdd, 15, 80, 'Diffuse', L00);
				var l01:HUISlider = new HUISlider (tmpAdd, 15, 100, 'Specular', L01);
				l00.setSliderParams(0, 1, CurrentLight.diffuse );
				l01.setSliderParams(0, 10, CurrentLight.specular );
				l00.labelPrecision=2;
				var txt00:Label=new Label(tmpAdd, 15, 120, "Color");
				var col:ColorChooser=new ColorChooser(tmpAdd,70,120,CurrentLight.color, LightChangeColor); col.usePopup=(true);
				
				sep2(tend, tend-40, 10, true);
				upbg(tend+5)
				
			}
			private function L00(e:Event):void {CurrentLight.diffuse= e.target.value;}
			private function L01(e:Event):void {CurrentLight.specular= e.target.value;}
			private function LightChangeColor(e:Event):void { CurrentLight.color=e.target.value; }
			private function L02(e:Event):void { O.Lights.DayCycle(e.target.value, O.Lights.angle2); }
			private function L03(e:Event):void { O.Lights.DayCycle(O.Lights.angle, e.target.value); }
			// END LIGHT
			
			/////////////////////////////////////////
			//               MATERIAL              //
			//             ALL SETTING             //
			/////////////////////////////////////////
			private function Material() : void
			{
				
				var Liste:Array=new Array();
				for each(var m:* in O.MatListe)Liste.push(m.name)
				var comp:ComboBox=new ComboBox(content,40, 45,"scene Material",Liste)
				comp.width=140;
				comp.addEventListener(Event.SELECT, select_Material);
				tmpAdd=new Sprite();
				content.addChild(tmpAdd)
				sep2(70, 30, 10, true);
				upbg(75)
			}
			private function select_Material(e:Event):void { 
				DeleteFilter();
				var n:int=e.target.selectedIndex;
				CurrentMaterial=O.MatListe[n];
				switch(n){
					case 0: ;break;
				}
				var m00:HUISlider = new HUISlider (tmpAdd, 15, 80, 'Ambiant', M00);
				var m01:HUISlider = new HUISlider (tmpAdd, 15, 100, 'Specular', M01);
				var m02:HUISlider = new HUISlider (tmpAdd, 15, 120, 'Gloss', M02);
				m00.setSliderParams(0, 1, CurrentMaterial.ambient)
				m01.setSliderParams(0, 10, CurrentMaterial.specular)
				m02.setSliderParams(0, 100, CurrentMaterial.gloss)
				m00.labelPrecision=2;
				m01.labelPrecision=1;
				m02.labelPrecision=0;
				
				sep2(145, 105, 10, true);
				upbg(150)
			}
			private function M00(e:Event):void {CurrentMaterial.ambient= e.target.value;}
			private function M01(e:Event):void {CurrentMaterial.specular= e.target.value;}
			private function M02(e:Event):void {CurrentMaterial.gloss=e.target.value;}
			// END MATERIAL
			
			/////////////////////////////////////////
			//               PHYSICS               //
			//             ALL SETTING             //
			/////////////////////////////////////////
			private function Physic() : void
			{
				var txt00:Label
				var radio1:RadioButton = new RadioButton(content, 110, 50, "on", true, phyOn);radio1.groupName="A";
				var radio2:RadioButton = new RadioButton(content, 140, 50, "off", false, phyOff);radio2.groupName="A";
				if(O.physicEngine=="bullet"){
					txt00=new Label(content, 15, 45, "Bullet engine");
					var k00:HUISlider = new HUISlider (content, 15, 65, 'Times', K00);
					var k01:HUISlider = new HUISlider (content, 15, 85, 'Steps', K01);
					var k02:HUISlider = new HUISlider (content, 15, 105, 'MaxSteps', K02);
					k00.setSliderParams(0, 10, O.physics.times*100 );
					k01.setSliderParams(0, 10, O.physics.Steps*100 );
					k02.setSliderParams(0, 60, O.physics.MaxSteps );
					k00.labelPrecision=2;
					k01.labelPrecision=2;
					k02.labelPrecision=0;
					var txt01:Label=new Label(content, 15, 130, "Bullet type");
					var radio3:RadioButton = new RadioButton(content, 85, 135, "1", false, gx00);radio3.groupName="B";
					var radio4:RadioButton = new RadioButton(content, 115, 135, "2", true, gx01);radio4.groupName="B";
					var radio5:RadioButton = new RadioButton(content, 145, 135, "3", false, gx02);radio5.groupName="B";
					var radio6:RadioButton = new RadioButton(content, 175, 135, "4", false, gx03);radio6.groupName="B";
					var g00:HUISlider = new HUISlider (content, 15, 150, 'Gravity', Grav);
					g00.setSliderParams(-20, 20, O.physics.world.gravity.y );
					g00.labelPrecision=0;
					
				} else if (O.physicEngine=="jiglib"){
					txt00=new Label(content, 15, 45, "Jiglib engine");
				}
				tmpAdd=new Sprite();
				content.addChild(tmpAdd);
				sep2(180, 140, 10, true);
				upbg(185);
				
			}
			private function K00(e:Event):void {O.physics.times= e.target.value/100;}
			private function K01(e:Event):void {O.physics.Steps= e.target.value/100;}
			private function K02(e:Event):void {O.physics.MaxSteps=e.target.value;}
			private function phyOn(e:Event):void {O.physics.actif=true;}
			private function phyOff(e:Event):void {O.physics.actif=false;}
			private function Grav(e:Event):void {O.physics.setGravity(e.target.value);}
			private function gx00(e:Event):void {O.physics.Minition=0;}
			private function gx01(e:Event):void {O.physics.Minition=1;}
			private function gx02(e:Event):void {O.physics.Minition=2;}
			private function gx03(e:Event):void {O.physics.Minition=3;}
			// END PHYSICS
			
			
			private var CurrentMaterial:*//DefaultMaterialBase;
	        private var CurrentLight:*//LightBase;
			private var linecolor:int=0x623436;
			private var linealpha:Number=1;
			private var tmpAdd:Sprite;
			private var Q:int=1;
			//END\\
		}}